cmake_minimum_required(VERSION 3.5)
set(PROJECT_NAME MkMediaServer)
project(${PROJECT_NAME})

set(VERSION "1.0.0.0")
option(BUILD_UT "build ut" OFF)
option(BUILD_TEST "build test" OFF)
set(ROOT_PATH ${CMAKE_CURRENT_LIST_DIR})
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_LIST_DIR}/bin)
configure_file(${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}Config.h.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.h @ONLY)

if (BUILD_UT)
    add_subdirectory(Ut)
endif()

add_definitions(-std=c++11)
if(MSVC)
    add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS -D__STDC_LIMIT_MACROS)
    list(APPEND LIBS ws2_32 winmm)
else(MSVC)
    list(APPEND LIBS pthread dl)
endif(MSVC)

find_package(MkCore QUIET)
if(MkCore_FOUND)
	include_directories(${MkCore_INCLUDE_DIRS})
	link_directories(${MkCore_LIBRARIE_PATH})
	LIST(APPEND LIBS ${MkCore_LIBRARIES})   
else()
	message(FATAL_ERROR "please install MkCore(https://gitee.com/chaigec_admin/MkCore.git) first")
endif()

find_package(jsoncpp QUIET)
if(jsoncpp_FOUND)
	if(MSVC)
        get_target_property(JSON_INC_PATH jsoncpp_lib_static INTERFACE_INCLUDE_DIRECTORIES)
        include_directories(${JSON_INC_PATH})
        message("FOUND CONFIG: ${jsoncpp_LIBRARIES}")
        message("INCLUDE DIRS: ${JSON_INC_PATH}")
        message("LIBRARIES: ${jsoncpp_INCLUDE_DIRS}")
        LIST(APPEND LIBS jsoncpp_lib_static)
    else()
        INCLUDE(FindPkgConfig)
        pkg_check_modules(JSONCPP REQUIRED jsoncpp)
        include_directories(${JSONCPP_INCLUDE_DIRS})
        message("include path:${JSONCPP_INCLUDE_DIRS}")
        message("lib path:${JSONCPP_LIBRARIES}")
        LIST(APPEND LIBS ${JSONCPP_LIBRARIES})
    endif()	   
else()
	message(FATAL_ERROR "please install jsoncpp  first")
endif()

if(MSVC)
	find_package(tinyxml2 QUIET)
	if(NOT tinyxml2_FOUND)
		message(FATAL_ERROR "please install tinyxml2(https://github.com/leethomason/tinyxml2)  first")
	endif()
	include_directories("C:/Program Files (x86)/tinyxml2/include")
	link_directories("C:/Program Files (x86)/tinyxml2/lib")
endif(MSVC)
list(APPEND LIBS tinyxml2)

include_directories(${CMAKE_CURRENT_BINARY_DIR})
file (GLOB_RECURSE SOURCES ${CMAKE_CURRENT_LIST_DIR}/MkMediaServer.cpp
                           ${CMAKE_CURRENT_LIST_DIR}/main.cpp)
file (GLOB_RECURSE HEADERS ${CMAKE_CURRENT_LIST_DIR}/MkMediaServer.h)

add_executable(MkMediaServer ${SOURCES} ${HEADERS})
target_link_libraries(MkMediaServer ${LIBS})

if (BUILD_TEST)
    add_subdirectory(Test)
    SET_TARGET_PROPERTIES(TestWsFlvPlayer TestRtmpPlayer TestRtmpPublisher TestGbPublisher PROPERTIES FOLDER Test)
endif()